{include file="public/head" /}
<body>
{include file="public/menu" /}
<div class="pagelogin commonPage">
    <div class="bg" id="bg"></div>
    <div class="box">
        <div class="subnav" id="subnav" >
            <span {if condition="$ac eq 'login'"}class="ac"{/if}>用户登录</span>
            <span {if condition="$ac eq 'register'"}class="ac"{/if}>用户注册</span>
        </div>
        <div class="main">
            <!--登录-->
            <form action="" id="login" {if condition="$ac eq 'login'"}class="acform"{/if} onSubmit="return false;">
            <div class="user commonInput">
                <input type="text" placeholder="请输入手机号" id="tel2">
                <input type="hidden" name="lockm" value="" id="lockm">
            </div>
            <div class="password commonInput">
                <input type="password" placeholder="请输入密码" id="password2">
                <input type="hidden" name="lockcode" value="" id="lockcode">
            </div>
            <div class="getpiccode commonInput">
                <input type="text" class="recharge-amount amount1" name="code" placeholder="图形验证码" />
                <img src="{:captcha_src()}" id="code1" alt="captcha" onclick="this.src='{:captcha_src()}?rnd=' + Math.random();" />
            </div>
            <div class="agree">
                <div class="left">
                    <input type="checkbox" checked id="agress"><label for="agress">我已阅读并同意<a href="javaScript:(0)" onclick="yhzc()">《用户注册服务协议》</a>
                    <a href="javaScript:(0)" onclick="tzr()">《投资人服务协议》</a>
                    <a href="javaScript:(0)" onclick="fxts()">《投资风险提示书》</a>
                    <a href="javaScript:(0)" onclick="dzqm()">《电子签名授权协议》</a>
                    <a href="javaScript:(0)" onclick="wtqm()">《委托快捷签署协议》</a>

                </label>
                </div>
                <div class="right">
                    <a href="{:url('Login/findpassword')}">忘记密码？</a>
                </div>
            </div>
            <input type="submit" value="登录" onclick="checkInfo2()">
            </form>
            <!--注册-->
            <form action="" id="register" {if condition="$ac eq 'register'"}class="acform"{/if}  onSubmit="return false;">
            <div class="user commonInput">
                <input type="text" name="mobile" placeholder="请输入手机号" id="tel1">
            </div>
            <div class="password commonInput">
                <input type="password" name="password" placeholder="请设置密码" id="password1" />
            </div>
            <div class="password commonInput">
                <input type="password" placeholder="请再次确认密码" id="surepassword1" />
            </div>
            {if input('invite')}
            <div class="commonInput" id="getpiccode2">
                <input type="text" placeholder="邀请码" name="invite" id="invite" value="{:input('invite')}" {if condition="input('invite')"}readonly{/if} />
            </div>
            {/if}
            <div class="commonInput getpiccode">
                <input type="text" class="recharge-amount amount1" id="txcode" placeholder="图形验证码" style="padding-left: 20px !important;"/>
                <img src="{:captcha_src()}" id="code" alt="captcha" onclick="this.src='{:captcha_src()}?rnd=' + Math.random();" />
            </div>
            <div class="commonInput" id='getcode_box'>
                <input type="text" class="recharge-amount amount1" name="mobile_code" placeholder="短信验证码" />
                <button class='getcode' id="getcode" onclick="getCode()">获取验证码</button>
            </div>
            <div class="agree">
                <div class="left">
                    <input type="checkbox" id="agree" checked>
                    <label for="agree">我已阅读并同意<a href="javaScript:(0)" onclick="yhzc()">《用户注册服务协议》</a>
                        <a href="javaScript:(0)" onclick="tzr()">《投资人服务协议》</a>
                        <a href="javaScript:(0)" onclick="fxts()">《投资风险提示书》</a>
                        <a href="javaScript:(0)" onclick="dzqm()">《电子签名授权协议》</a>
                        <a href="javaScript:(0)" onclick="wtqm()">《委托快捷签署协议》</a></label>
                </div>
                <div class="right" id="fgt">
                    <a href="{:url('Login/findpassword')}" >忘记密码？</a>
                </div>
            </div>
            <input type="submit" value="立即注册" onclick="checkInfo1()">
            </form>
        </div>
    </div>
</div>
</body>
{include file="public/load_bottom" /}
{load href="__static__/hry/js/Base64.js" /}
<script>

$(function () {
    var storage=window.localStorage;
    const invite=$("#invite").val();
    if(invite!=''&&typeof(invite)!='undefined'){
        console.log(invite);
        storage.invite=invite;
    }else{
        if(storage.invite!=''&&typeof(storage.invite)!='undefined'){
            // $("#invite").val(storage.invite);
            window.location.href='/login/register/invite/'+storage.invite;
        }
    }
    {if condition="$ac eq 'register'"}
        $('#fgt').hide()
    {else/}
        $('#fgt').show()
    {/if}

    setBg()
    var nav = $('#subnav').find('span')
    var form = $('.main form')
    nav.click(function () {
        var index = $(this).index()
        if(index==1){
            $('#fgt').hide()
        }else{
            $('#fgt').show()
        }
        $(this).addClass('ac').siblings().removeClass('ac')
        form.eq(index).addClass('acform').siblings().removeClass('acform')
    })
    $('.mask').click(function () {
        //$('.alert').fadeOut(300)
		window.location.href = 'http://' + window.location.host;
    })
})
function setBg() {
        var h = $(window).height()
        $('#bg').css('height',h-110)
    }

function checkInfo1() {
        var tel = $('#tel1')
        var password1 = $('#password1')
        var surepassword = $('#surepassword1')
        var agree = $('#agree')
		var mobileCode = $("input[name='mobile_code']").val();
		var phoneReg = /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/;
		var passReg = /^(?!([a-zA-Z]+|\d+)$)[a-zA-Z\d]{6,20}$/;
        if(!phoneReg.test(tel.val())){
            layer.msg('请输入正确的手机号')
            tel.focus()
            return false
        }
		else if(!passReg.test(password1.val())){
            layer.msg('请输入6-20位数字+字母的密码')
            password1.focus()
            return false
		}
        else if(surepassword.val()==''){
            layer.msg('请确认密码！')
            surepassword.focus()
            return false
        }
		else if(mobileCode == ''){
            layer.msg('请输入短信验证码')
            return false
		}
        else if(!agree.is(':checked')){
            layer.msg('尚未同意协议！')
            err.fadeIn(300)
            setTimeout(function(){
                err.fadeOut(300)
            },1000)
            return false
        }
        else if(password1.val()!=surepassword.val()){
            layer.msg('两次密码不一致！')
            return false
        }
		var fromData = $('#register').serialize();
		$.ajax({
			url:"{:url('Login/register')}",
			type:"POST",
			dataType:"JSON",
			data:fromData,
			success:function(msg){
				if(msg.status == 1){
					layer.msg(msg.info);
					window.location = msg.url;
				}else{
					layer.msg(msg.info);
				}
			}

		})
    }

function getCode(){
	var code = $("#txcode").val();
	var mobile = $("#tel1").val();
	var phoneReg = /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/;
	if(!phoneReg.test(mobile)){
		layer.msg('请输入正确的手机号');
		return false;
	}
	if(code.length != 4){
		layer.msg('请输入正确图形验证码');
		return false;
	}
	settime();
	$.ajax({
		url: "{:url('Login/sendcode')}",
		type: "POST",
		dataType: "JSON",
		data: {mobile:mobile,code:code},
		success: function(msg){
			layer.msg(msg.info);
			if(msg.status != 1){
				countdown=0;
				$("#getcode").attr('disabled',false)
				$("#getcode").text("获取验证码");
			}
			return false;
		}
	})
}

var countdown=60;
function settime(){
	var val = $("#getcode");
	if (countdown == 0) {
		val.attr('disabled',false)
		val.text("获取验证码");
		countdown = 60;
	} else {
		val.attr('disabled',true)
		val.text(countdown+"s");
		countdown--;
		setTimeout(function() {
			settime()
		},1000)
	}

}

function checkInfo2() {
    var tel = $('#tel2')
    var password1 = $('#password2')
    var err = $('#err2')
    var agree = $('#agress')
    if(tel.val()==''){
        layer.msg('请输入手机号码！')
        err.fadeIn(300)
        setTimeout(function(){
            err.fadeOut(300)
        },1000)
        tel.focus()
        return false
    }
    else if(password1.val()==''){
        layer.msg('请输入密码！')
        err.fadeIn(300)
        setTimeout(function(){
            err.fadeOut(300)
        },1000)
        password1.focus()
        return false
    }
    else if(!agree.is(':checked')){
        layer.msg('尚未同意协议！')
        err.fadeIn(300)
        setTimeout(function(){
            err.fadeOut(300)
        },1000)
        return false
    }
	var lockm = Base64.encode(tel.val())
	var lockcode = Base64.encode(password1.val())
	$("#lockm").val(lockm)
	$("#lockcode").val(lockcode)
	var fromData = $('#login').serialize();
	$.ajax({
		url:"{:url('Login/loginin')}",
		type:"POST",
		dataType:"JSON",
		data:fromData,
		success:function(msg){
			if(msg.status == 1){
				layer.msg(msg.info);
				err.fadeIn(300)
				setTimeout(function(){
					err.fadeOut(300)
				},1000)
				window.location = msg.url;
			}else{
				layer.msg(msg.info);
				err.fadeIn(300)
				setTimeout(function(){
					err.fadeOut(300)
				},1000)
			}
		}

	})
}

function yhzc(){
	layer.open({
	  type: 2,
	  title: '用户注册服务协议',
      btn: [ '关闭'],
	  shadeClose: true,
	  shade: 0.8,
	  area: ['80%', '90%'],
	  content: '{:url("Login/agreement")}' //iframe的url
	});
}

function tzr(){
    layer.open({
        type: 2,
        title: '投资人服务协议',
        btn: [ '关闭'],
        shadeClose: true,
        shade: 0.8,
        area: ['80%', '90%'],
        content: '{:url("Login/service")}' //iframe的url
    });
}

function fxts(){
    layer.open({
        type: 2,
        title: '投资风险提示书',
        btn: [ '关闭'],
        shadeClose: true,
        shade: 0.8,
        area: ['80%', '90%'],
        content: '{:url("Login/warning")}' //iframe的url
    });
}

function dzqm(){
    layer.open({
        type: 2,
        title: '电子签名授权协议',
        btn: [ '关闭'],
        shadeClose: true,
        shade: 0.8,
        area: ['80%', '90%'],
        content: '{:url("Login/dzqm")}' //iframe的url
    });
}

function wtqm(){
    layer.open({
        type: 2,
        title: '委托快捷签署协议',
        btn: [ '关闭'],
        shadeClose: true,
        shade: 0.8,
        area: ['80%', '90%'],
        content: '{:url("Login/wtqm")}' //iframe的url
    });
}
</script>
<style>
    .layermchild{ -webkit-overflow-scrolling: touch;}
</style>
</html>